package com.me.testcustomview;

import java.util.ArrayList;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBarDrawerToggle;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;

public class MainActivity extends SherlockActivity {
private GridView gridViewTest;
private ActionBar bar;
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		String list[] = {"Câu 2", "Câu 3", "Câu 5", "Câu 7", "Câu 9", "Câu 1", "Câu 1", "Câu 1", "Câu 1"};
		
		drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		drawerList = (ListView) findViewById(R.id.left_drawer);
		
		drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
		drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, list));
		/*drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.ab_title, R.string.ab_subtitle)
		{
            public void onDrawerClosed(View view) {
                bar.setTitle(getTitle());
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                bar.setTitle("drawer");
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };*/
		
		drawerToggle = new ActionBarDrawerToggle(this, getSupportActionBar(), drawerLayout, R.drawable.ic_drawer, R.string.ab_title, R.string.ab_subtitle)
		{
            public void onDrawerClosed(View view) {
                bar.setTitle(getTitle());
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                bar.setTitle("drawer");
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
		
        drawerLayout.setDrawerListener(drawerToggle);
		
		bar = getSupportActionBar();
		bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME);
		bar.setHomeButtonEnabled(true);
		bar.setDisplayHomeAsUpEnabled(true);
		bar.setDisplayShowCustomEnabled(true);
		//LayoutInflater inflater = LayoutInflater.from(this);
		//bar.setSubtitle("Câu 1");
		//bar.setDisplayShowTitleEnabled(true);
		//bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
		//String list[] = {"Câu 2", "Câu 3", "Câu 5", "Câu 7", "Câu 9", "Câu 1", "Câu 1", "Câu 1", "Câu 1"};
		ArrayList<String> data = new ArrayList<String>();
		for (int i = 0; i<15; i++) data.add(new String("Câu " + i));
		
		AbExamTitle examTitle = new AbExamTitle(this, "ncfeoinoicenionfoienfioneoif", data);
		bar.setCustomView(examTitle);
		
		MyAdapter adapter = new MyAdapter(this, 0, 1, "Hoá học", data);
		
		//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, list );
		//adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
		//bar.setListNavigationCallbacks(adapter, null);
		//bar.setDisplayShowHomeEnabled(false);
		gridViewTest = (GridView) findViewById(R.id.gridViewTest);
		gridViewTest.setAdapter(new SubjectAdapter(this, AppUtil.listSubject));
		//gridViewTest.setClickable(true);
		//Toast.makeText(getBaseContext(), "cdcd", Toast.LENGTH_SHORT).show();
		gridViewTest.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int pos,
					long id) {
				SubjectCategory category = (SubjectCategory)v;
				Toast.makeText(getBaseContext(),category.getSubjectId() , Toast.LENGTH_SHORT).show();
				
			}
		});
	
		
	}
	
	@Override
		public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
			final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
			inflater.inflate(R.menu.main, menu);
			return true;
		}
	
	@Override
		public boolean onOptionsItemSelected(MenuItem item) {
			//if (drawerToggle.onOptionsItemSelected((android.view.MenuItem)item)) return true;
		if (drawerToggle.onOptionsItemSelected(item)) return true;
			return super.onOptionsItemSelected(item);
		}
	
	@Override
		protected void onPostCreate(Bundle savedInstanceState) {
			super.onPostCreate(savedInstanceState);
			drawerToggle.syncState();
		}
	
	@Override
		public void onConfigurationChanged(Configuration newConfig) {
			super.onConfigurationChanged(newConfig);
			drawerToggle.onConfigurationChanged(newConfig);
		}


}
